package com.example.xxtautosignjava.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.xxtautosignjava.common.R;
import com.example.xxtautosignjava.entity.IndexShowImg;
import com.example.xxtautosignjava.service.IndexShowImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lee
 * @since 2022-10-14
 */
@RestController
@RequestMapping("/xxt/index-show-img")
public class IndexShowImgController {

    @Autowired
    IndexShowImgService service;

    @GetMapping("getImgList")
    public R getImgList() {
        List<IndexShowImg> list = service.list();
        List<String> imgList=new ArrayList<>();
        List<String> links=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
           imgList.add(list.get(i).getImgUrl()) ;
           links.add(list.get(i).getLinks());
        }

        return R.ok().data("imgList", imgList).data("links",links);
    }

    @PostMapping("addImgList")
   public R addImgList(@RequestBody IndexShowImg indexShowImg) {
        boolean save = service.save(indexShowImg);
        return R.ok();

    }
    @PostMapping("updateList")
    public R updateList(@RequestBody IndexShowImg indexShow){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("id",indexShow.getId());
        boolean update = service.update(wrapper);
        return R.ok();
    }
    @DeleteMapping("deleteById/{id}")
    public R delete(@PathVariable String id){
        boolean b = service.removeById(id);return R.ok();

    }

}

